// pages/choosedishes/choosedishes.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    dishes: [],
    defaulturl: "../../images/default_img.png",
    indexp: 0,
    indexc: 0,
    weekday: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var dishes = JSON.parse(options.disheststr)
    var indexp = options.indexp
    var indexc = options.indexc
    var weekday = options.weekday
    this.setData({
      dishes: dishes,
      indexp: indexp,
      indexc: indexc,
      weekday: weekday
    })
  },

  btnclick: function (e) {
    var index = e.currentTarget.dataset.index;
    var dishes = this.data.dishes
    var obj = {
      meal_pic_id: dishes[index].meal_pic_id,
      meal_name: dishes[index].meal_name,
      attachmentUrl:dishes[index].attachmentUrl,
    }
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1]; //当前页面
    var prevPage = pages[pages.length - 2]; //上一个页面

    var mealset = prevPage.data.mealset
    var list = []
    if (this.data.weekday == 1) {
      list = mealset[this.data.indexp].zhouyilist
    } else if (this.data.weekday == 2) {
      list = mealset[this.data.indexp].zhouerlist
    } else if (this.data.weekday == 3) {
      list = mealset[this.data.indexp].zhousanlist
    } else if (this.data.weekday == 4) {
      list = mealset[this.data.indexp].zhousilist
    } else if (this.data.weekday == 5) {
      list = mealset[this.data.indexp].zhouwulist
    } else if (this.data.weekday == 6) {
      list = mealset[this.data.indexp].zhouliulist
    } else if (this.data.weekday == 7) {
      list = mealset[this.data.indexp].zhouqilist
    }
    list[this.data.indexc] = obj
    mealset.list = list
    prevPage.setData({
      mealset: mealset
    })
    wx.navigateBack();

  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})